package com.yunxin.core.application.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunxin.core.application.admin.team.TeamTaskDistribute;
import com.yunxin.core.application.admin.team.TeamTaskDistributeCount;
import com.yunxin.core.application.service.PageQueryCountService;
import com.yunxin.core.infra.persistence.mapper.order.OrderTeamTaskDetailMapper;
import com.yunxin.core.infra.persistence.mapper.order.PageQueryCountMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
@RequiredArgsConstructor
public class PageQueryCountServiceImpl extends ServiceImpl<PageQueryCountMapper,TeamTaskDistribute> implements PageQueryCountService {


    /**
     * 团队分配数量统计
     *
     * @return
     */
    @Override
    public IPage<TeamTaskDistribute> pageQueryCount(TeamTaskDistributeCount dto) {

        if (Objects.isNull(dto.getPageNum())) dto.setPageNum(1);
        if (Objects.isNull(dto.getPageSize())) dto.setPageSize(10);
        QueryWrapper<TeamTaskDistribute> wrapper = new QueryWrapper<>();
        wrapper.like(Objects.nonNull(dto.getTeamName()),"team_name",dto.getTeamName());
        wrapper.like(Objects.nonNull(dto.getSysUserId()),"sys_user_id",dto.getSysUserId());
        wrapper.like(Objects.nonNull(dto.getUserName()),"user_name",dto.getUserName());
        wrapper.eq(Objects.nonNull(dto.getTeamId()),"team_id",dto.getTeamId());
        wrapper.orderByDesc("creat_time");
        //时间筛选
        if (null != dto.getEndTime() && dto.getStartTime() != null) {
            wrapper.between("creat_time",dto.getStartTime(),dto.getEndTime());
        }
        //查询
        IPage<TeamTaskDistribute> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        return this.baseMapper.selectPage(page,wrapper);
    }
}
